package org.chronologger.poppaea.client;

import org.chronologger.poppaea.client.domain.ChronologyData;

public class LinearPositionResolver extends PositionResolver {

	public LinearPositionResolver(ChronologyData data) {
		super(data);
	}

	@Override
	public int getWidth() {
		return getPosition(getData().endTime.getTime());
	}
	
	@Override
	public int getPosition(Long time) {
		final Long startTime = getData().startTime.getTime();
		return (int) Math.round((time-startTime) / 86400000.0 * preferredResolution); 
	}

	@Override
	public Long getTime(int position) {
		final Long startTime = getData().startTime.getTime();
		final Long timeDiff = getData().endTime.getTime() - startTime; 
		final double timeSize = timeDiff / 86400000.0 * preferredResolution;
		return Math.round(startTime + timeDiff / (double)timeSize * position); 
	}

}
